﻿using System;

public class Student
{
    private int facultyNumber;
    private string name;

    public Student(string name, int facultyNumber)
    {
        CheckName(name);
        CheckFacultyNumber(facultyNumber);
        this.name = name;
        this.facultyNumber = facultyNumber;
    }

    public int FacultyNumber
    {
        get
        {
            return facultyNumber;
        }
        set
        {
            CheckFacultyNumber(value);
            facultyNumber = value;
        }
    }

    public string Name
    {
        get
        {
            return name;
        }
        set
        {
            CheckName(value);
            name = value;
        }
    }

    public override bool Equals(object obj)
    {
        Student studentToCompare = obj as Student;
        bool areEqual = studentToCompare.FacultyNumber == this.FacultyNumber &&
                        studentToCompare.Name.Equals(this.Name);
        return areEqual;
    }

    public override int GetHashCode()
    {
        int hashCode = this.facultyNumber.GetHashCode();
        return hashCode;
    }

    public override string ToString()
    {
        return string.Format("facultyNumber: {0}, name: {1}",
                             facultyNumber,
                             name);
    }

    private void CheckFacultyNumber(int facultyNumber)
    {
        if (facultyNumber < 10000 || facultyNumber > 99999)
        {
            throw new ArgumentOutOfRangeException(
                string.Format("Faculty number {0} should be between 10000 and 99999", facultyNumber));
        }
    }

    private void CheckName(string name)
    {
        if (name == null)
        {
            throw new ArgumentNullException("Name cannot be empty");
        }
        if (name == string.Empty)
        {
            throw new ArgumentException("Name cannot be empty");
        }
    }
}